package com.zoran.study.spring.controller.interceptors;

import org.springframework.lang.Nullable;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * MySecondInterceptor
 * 可以通过继承HandlerInterceptorAdapter,默认方式都是空实现
 *
 * @author zouxm
 * @date 16/12/29
 */

public class MySecondInterceptor extends HandlerInterceptorAdapter {

    //在目标方法之前调用,如果返回false,则不会调用目标方法,也不会调用后续的拦截器
    //如果此方法返回true,则对应的afterCompletion一定会被调用,返回false不会调用
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("MySecondInterceptor preHandle");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        System.out.println("MySecondInterceptor postHandle");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        System.out.println("MySecondInterceptor afterCompletion");
    }
}
